home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / guigfxlib / examples / shadebobs / source / shadebobs.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  15KB  |  652 lines

  1. /*********************************************************************
  2. ----------------------------------------------------------------------
  3.  
  4.     Shade Bobs 1.0
  5.     
  6.     a test for
  7.     guigfx.library/DirectDrawTrueColor()
  8.  
  9. ----------------------------------------------------------------------
  10. *********************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include <math.h>
  16. #include <time.h>
  17.  
  18. #include <utility/tagitem.h>
  19. #include <workbench/startup.h>
  20. #include <workbench/workbench.h>
  21. #include <intuition/intuition.h>
  22. #include <guigfx/guigfx.h>
  23. #include <exec/memory.h>
  24.  
  25. #include <clib/macros.h>
  26.  
  27. #include <proto/exec.h>
  28. #include <proto/intuition.h>
  29. #include <proto/graphics.h>
  30. #include <proto/utility.h>
  31. #include <proto/guigfx.h>
  32. #include <proto/wb.h>
  33. #include <proto/dos.h>
  34. #include <proto/intuition.h>
  35. #include <proto/guigfx.h>
  36.  
  37. #include "misc.h"
  38. #include "timer.h"
  39.  
  40. /*------------------------------------------------------------------*/
  41.  
  42. long __stack = 20000;
  43. #define PROGNAME                "RGB ShadeBobs"
  44. #define    __VERSION__                " 1.0"
  45. static char versionstring[] = "$VER: " PROGNAME __VERSION__ "";
  46. struct Library *GuiGFXBase = NULL;
  47.  
  48. /*********************************************************************
  49. ----------------------------------------------------------------------
  50.  
  51.     global
  52.  
  53. ----------------------------------------------------------------------
  54. *********************************************************************/
  55.  
  56. void CloseGlobal(void)
  57. {
  58.     CloseLibrary(GuiGFXBase);
  59.     GuiGFXBase = NULL;
  60. }
  61.  
  62. BOOL InitGlobal(void)
  63. {
  64.     GuiGFXBase = OpenLibrary("guigfx.library", GUIGFX_VERSION);
  65.  
  66.     srand(time(NULL));
  67.  
  68.     if (!GuiGFXBase)
  69.     {
  70.         GuiGFXBase = OpenLibrary("libs/guigfx.library", GUIGFX_VERSION);
  71.     }
  72.  
  73.     if (GuiGFXBase)
  74.     {
  75.         return TRUE;
  76.     }
  77.     
  78.     printf("*** could not open guigfx.library v%d.\n", GUIGFX_VERSION);
  79.  
  80.     CloseGlobal();
  81. }
  82.  
  83.  
  84. /*********************************************************************
  85. ----------------------------------------------------------------------
  86.  
  87.     void UpdateWindowParameters(mvwindow)
  88.  
  89.     get current window parameters
  90.  
  91. ----------------------------------------------------------------------
  92. *********************************************************************/
  93.  
  94. void UpdateWindowParameters(struct mvwindow *win)
  95. {
  96.     win->winleft = win->window->LeftEdge;
  97.     win->wintop = win->window->TopEdge;
  98.     win->winwidth = win->window->Width;
  99.     win->winheight = win->window->Height;
  100.     win->innerleft = win->window->BorderLeft;
  101.     win->innertop = win->window->BorderTop;
  102.     win->innerwidth = win->winwidth - win->innerleft - win->window->BorderRight;
  103.     win->innerheight = win->winheight - win->innertop - win->window->BorderBottom;
  104. }
  105.  
  106.  
  107. /*********************************************************************
  108. ----------------------------------------------------------------------
  109.  
  110.     DeleteMVWindow (mvwindow)
  111.  
  112. ----------------------------------------------------------------------
  113. *********************************************************************/
  114.  
  115. void DeleteMVWindow (struct mvwindow *win)
  116. {
  117.     if (win)
  118.     {
  119.         if (win->window)
  120.         {
  121.             Forbid();
  122.  
  123.             if (win->appwindow && win->appmsgport)
  124.             {
  125.                 struct AppMessage *appmsg;
  126.             
  127.                 while (appmsg = (struct AppMessage *) GetMsg(win->appmsgport))
  128.                 {
  129.                     ReplyMsg((struct Message *) appmsg);
  130.                 }
  131.             
  132.                 RemoveAppWindow(win->appwindow);
  133.             }
  134.     
  135.             DeleteMsgPort(win->appmsgport);
  136.  
  137.             Permit();
  138.  
  139.             CloseWindow(win->window);
  140.         }
  141.         
  142.         free(win);
  143.     }
  144. }
  145.  
  146.  
  147.  
  148. /*********************************************************************
  149. ----------------------------------------------------------------------
  150.  
  151.     mvwindow = CreateMVWindow (screen)
  152.  
  153. ----------------------------------------------------------------------
  154. *********************************************************************/
  155.  
  156. #define inserttag(x,t,d) {(x)->ti_Tag=(t);((x)++)->ti_Data=(ULONG)(d);}
  157.  
  158. struct mvwindow *CreateMVWindow (struct Screen *scr)
  159. {
  160.     struct mvwindow *win;
  161.     
  162.     if (win = malloc(sizeof(struct mvwindow)))
  163.     {
  164.         BOOL success = FALSE;
  165.         struct TagItem *taglist;
  166.  
  167.         memset(win, 0, sizeof(struct mvwindow));
  168.  
  169.         win->screen = scr;
  170.  
  171.         if(win->appmsgport = CreateMsgPort())
  172.         {
  173.             win->appSignal = 1L << win->appmsgport->mp_SigBit;
  174.  
  175.             if(taglist = AllocateTagItems(20))
  176.             {
  177.                 UWORD visibleWidth, visibleHeight, visibleMidX, visibleMidY;
  178.                 UWORD visibleLeft, visibleTop;
  179.                 WORD winwidth, winheight, wintop, winleft;
  180.                 struct TagItem *tp = taglist;
  181.                 ULONG modeID;
  182.         
  183.                 visibleWidth = scr->Width;
  184.                 visibleHeight = scr->Height;
  185.         
  186.                 if ((modeID = GetVPModeID(&scr->ViewPort)) != INVALID_ID)
  187.                 {
  188.                     DisplayInfoHandle dih;
  189.             
  190.                     if(dih = FindDisplayInfo(modeID))
  191.                     {
  192.                         struct DimensionInfo di;    
  193.             
  194.                         if(GetDisplayInfoData(dih, (UBYTE*) &di, sizeof(di), DTAG_DIMS, modeID))
  195.                         {
  196.                             visibleWidth = di.TxtOScan.MaxX - di.TxtOScan.MinX;
  197.                             visibleHeight = di.TxtOScan.MaxY - di.TxtOScan.MinY;
  198.                         }
  199.                     }
  200.                 }
  201.         
  202.                 visibleLeft = -scr->ViewPort.DxOffset;
  203.                 visibleTop = -scr->ViewPort.DyOffset;
  204.  
  205.                 visibleMidX = visibleWidth/2 - scr->ViewPort.DxOffset;
  206.                 visibleMidY = visibleHeight/2 - scr->ViewPort.DyOffset;
  207.         
  208.                 winwidth = visibleWidth / 2;
  209.                 winheight = visibleHeight / 2;
  210.                 inserttag(tp, WA_Width, winwidth);
  211.                 inserttag(tp, WA_Height, winheight);
  212.         
  213.                 winleft = visibleMidX - winwidth/2;
  214.                 wintop = visibleMidY - winheight/2;
  215.                 inserttag(tp, WA_Left, winleft);
  216.                 inserttag(tp, WA_Top, wintop);
  217.     
  218.                 win->otherwinpos[0] = visibleLeft;
  219.                 win->otherwinpos[1] = visibleTop;
  220.                 win->otherwinpos[2] = visibleWidth;
  221.                 win->otherwinpos[3] = visibleHeight;
  222.  
  223.                 inserttag(tp, WA_Zoom, &win->otherwinpos);
  224.  
  225.                 inserttag(tp, WA_PubScreen, scr);
  226.         
  227.                 inserttag(tp, WA_Title, DEFAULT_WINTITLE);
  228.         
  229.                 inserttag(tp, WA_NewLookMenus, TRUE);
  230.         
  231.         
  232.                 inserttag(tp, WA_Flags, 
  233.                             WFLG_SIZEBBOTTOM | WFLG_DRAGBAR | 
  234.                             WFLG_SIZEGADGET | WFLG_DEPTHGADGET | WFLG_ACTIVATE |
  235.                             WFLG_CLOSEGADGET | WFLG_SIMPLE_REFRESH);
  236.  
  237.                 inserttag(tp, WA_IDCMP, 
  238.                             IDCMP_CLOSEWINDOW | IDCMP_MENUPICK | 
  239.                             IDCMP_NEWSIZE | IDCMP_ACTIVEWINDOW |
  240.                             IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_MOUSEBUTTONS);
  241.             
  242.                 inserttag(tp, WA_MinWidth, DEFAULT_MINWIDTH);
  243.                 inserttag(tp, WA_MinHeight, DEFAULT_MINHEIGHT);
  244.                 inserttag(tp, WA_MaxWidth, DEFAULT_MAXWIDTH);
  245.                  inserttag(tp, WA_MaxHeight, DEFAULT_MAXHEIGHT);
  246.  
  247.                 inserttag(tp, TAG_DONE, 0);
  248.         
  249.                 if(win->window = OpenWindowTagList(NULL, taglist))
  250.                 {
  251.                     win->idcmpSignal = 1L << win->window->UserPort->mp_SigBit;
  252.                     UpdateWindowParameters(win);
  253.  
  254.                     win->appwindow = AddAppWindow(0, 0, win->window, win->appmsgport, NULL);
  255.  
  256.                     success = TRUE;
  257.                 }
  258.         
  259.                 FreeTagItems(taglist);
  260.             }
  261.         }
  262.         
  263.         if (!success)
  264.         {
  265.             DeleteMVWindow(win);
  266.             win = NULL;
  267.         }
  268.     }
  269.  
  270.     return win;
  271. }
  272.  
  273. #undef inserttag
  274.  
  275.  
  276.  
  277.  
  278. double sd1, sd2, sd3, sd4, sd5, sd6;
  279. double dd1, dd2, dd3, dd4, dd5, dd6;
  280. int intensity;
  281.  
  282. void initeffekt (ULONG *buffer)
  283. {
  284.     int x, y;
  285.     
  286.     double r1, g1, b1;
  287.     double r2, g2, b2;
  288.     double xr, xg, xb;
  289.     double dyr1, dyg1, dyb1, dyr2, dyg2, dyb2, dxr, dxg, dxb;
  290.  
  291.     sd1 = drand48() * 0.4 + 0.3;
  292.     sd2 = drand48() * 0.4 + 0.3;
  293.     sd3 = drand48() * 0.4 + 0.3;
  294.     sd4 = drand48() * 0.4 + 0.3;
  295.     sd5 = drand48() * 0.4 + 0.3;
  296.     sd6 = drand48() * 0.4 + 0.3;
  297.  
  298.     dd1 = drand48() * 0.3 + 0.1;
  299.     dd2 = drand48() * 0.3 + 0.1;
  300.     dd3 = drand48() * 0.3 + 0.1;
  301.     dd4 = drand48() * 0.3 + 0.1;
  302.     dd5 = drand48() * 0.3 + 0.1;
  303.     dd6 = drand48() * 0.3 + 0.1;
  304.  
  305.     intensity = rand() % 12 + 6;
  306.  
  307.     r1 = rand() % 255;
  308.     g1 = rand() % 255;
  309.     b1 = rand() % 255;
  310.  
  311.     r2 = rand() % 255;
  312.     g2 = rand() % 255;
  313.     b2 = rand() % 255;
  314.  
  315.     dyr1 = ((rand() % 255) - r1) / 128;
  316.     dyg1 = ((rand() % 255) - g1) / 128;
  317.     dyb1 = ((rand() % 255) - b1) / 128;
  318.     dyr2 = ((rand() % 255) - r2) / 128;
  319.     dyg2 = ((rand() % 255) - g2) / 128;
  320.     dyb2 = ((rand() % 255) - b2) / 128;
  321.  
  322.     for (y = 0; y < 128; ++y)
  323.     {
  324.         xr = r1;
  325.         xg = g1;
  326.         xb = b1;
  327.  
  328.         dxr = (r2 - r1) / 128;
  329.         dxg = (g2 - g1) / 128;
  330.         dxb = (b2 - b1) / 128; 
  331.     
  332.         for (x = 0; x < 128; ++x)
  333.         {
  334.             buffer[y*128+x] = ((int)xr << 16) + ((int)xg << 8) + (int)xb;
  335.             xr += dxr;
  336.             xg += dxg;
  337.             xb += dxb;
  338.         }
  339.         
  340.         r1 += dyr1;
  341.         g1 += dyg1;
  342.         b1 += dyb1;
  343.  
  344.         r2 += dyr2;
  345.         g2 += dyg2;
  346.         b2 += dyb2;
  347.     }
  348. }
  349.  
  350.  
  351. void effekt (ULONG *buffer)
  352. {
  353.     double pi2 = 6.283056;
  354.     int x, y, i;
  355.     UBYTE *bp;
  356.     double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  357.     static double sin1 = 0, sin2 = 0, sin3 = 0, sin4 = 0, sin5 = 0, sin6 = 0;
  358.  
  359.     #define SETPOS(x,y)    bp = ((UBYTE *)(buffer+((y)<<7)+(x)));
  360.     #define SHADEPIXEL(ir, ig, ib) bp++;*bp+++=ir;*bp+++=ig;*bp+++=ib;
  361.     #define SETBOB(x,y,ir,ig,ib)         \
  362.         SETPOS((x)-1, (y)-4);            \
  363.         SHADEPIXEL(ir, ig, ib);            \
  364.         SHADEPIXEL(ir, ig, ib);            \
  365.         SHADEPIXEL(ir, ig, ib);            \
  366.         SETPOS((x)-3, (y)-3);            \
  367.         SHADEPIXEL(ir, ig, ib);            \
  368.         SHADEPIXEL(ir, ig, ib);            \
  369.         SHADEPIXEL(ir, ig, ib);            \
  370.         SHADEPIXEL(ir, ig, ib);            \
  371.         SHADEPIXEL(ir, ig, ib);            \
  372.         SHADEPIXEL(ir, ig, ib);            \
  373.         SHADEPIXEL(ir, ig, ib);            \
  374.         SETPOS((x)-3, (y)-2);            \
  375.         SHADEPIXEL(ir, ig, ib);            \
  376.         SHADEPIXEL(ir, ig, ib);            \
  377.         SHADEPIXEL(ir, ig, ib);            \
  378.         SHADEPIXEL(ir, ig, ib);            \
  379.         SHADEPIXEL(ir, ig, ib);            \
  380.         SHADEPIXEL(ir, ig, ib);            \
  381.         SHADEPIXEL(ir, ig, ib);            \
  382.         SETPOS((x)-4, (y)-1);            \
  383.         SHADEPIXEL(ir, ig, ib);            \
  384.         SHADEPIXEL(ir, ig, ib);            \
  385.         SHADEPIXEL(ir, ig, ib);            \
  386.         SHADEPIXEL(ir, ig, ib);            \
  387.         SHADEPIXEL(ir, ig, ib);            \
  388.         SHADEPIXEL(ir, ig, ib);            \
  389.         SHADEPIXEL(ir, ig, ib);            \
  390.         SHADEPIXEL(ir, ig, ib);            \
  391.         SHADEPIXEL(ir, ig, ib);            \
  392.         SETPOS((x)-4, (y));                \
  393.         SHADEPIXEL(ir, ig, ib);            \
  394.         SHADEPIXEL(ir, ig, ib);            \
  395.         SHADEPIXEL(ir, ig, ib);            \
  396.         SHADEPIXEL(ir, ig, ib);            \
  397.         SHADEPIXEL(ir, ig, ib);            \
  398.         SHADEPIXEL(ir, ig, ib);            \
  399.         SHADEPIXEL(ir, ig, ib);            \
  400.         SHADEPIXEL(ir, ig, ib);            \
  401.         SHADEPIXEL(ir, ig, ib);            \
  402.         SETPOS((x)-4, (y)+1);            \
  403.         SHADEPIXEL(ir, ig, ib);            \
  404.         SHADEPIXEL(ir, ig, ib);            \
  405.         SHADEPIXEL(ir, ig, ib);            \
  406.         SHADEPIXEL(ir, ig, ib);            \
  407.         SHADEPIXEL(ir, ig, ib);            \
  408.         SHADEPIXEL(ir, ig, ib);            \
  409.         SHADEPIXEL(ir, ig, ib);            \
  410.         SHADEPIXEL(ir, ig, ib);            \
  411.         SHADEPIXEL(ir, ig, ib);            \
  412.         SETPOS((x)-3, (y)+2);            \
  413.         SHADEPIXEL(ir, ig, ib);            \
  414.         SHADEPIXEL(ir, ig, ib);            \
  415.         SHADEPIXEL(ir, ig, ib);            \
  416.         SHADEPIXEL(ir, ig, ib);            \
  417.         SHADEPIXEL(ir, ig, ib);            \
  418.         SHADEPIXEL(ir, ig, ib);            \
  419.         SHADEPIXEL(ir, ig, ib);            \
  420.         SETPOS((x)-3, (y)+3);            \
  421.         SHADEPIXEL(ir, ig, ib);            \
  422.         SHADEPIXEL(ir, ig, ib);            \
  423.         SHADEPIXEL(ir, ig, ib);            \
  424.         SHADEPIXEL(ir, ig, ib);            \
  425.         SHADEPIXEL(ir, ig, ib);            \
  426.         SHADEPIXEL(ir, ig, ib);            \
  427.         SHADEPIXEL(ir, ig, ib);            \
  428.         SETPOS((x)-1, (y)+4);            \
  429.         SHADEPIXEL(ir, ig, ib);            \
  430.         SHADEPIXEL(ir, ig, ib);            \
  431.         SHADEPIXEL(ir, ig, ib);
  432.  
  433.     sin1 += sd1; while (sin1 > pi2 || sin1 < 0) sin1 -= pi2;
  434.     sin2 += sd2; while (sin2 > pi2 || sin2 < 0) sin2 -= pi2;
  435.     sin3 += sd3; while (sin3 > pi2 || sin3 < 0) sin3 -= pi2;
  436.     sin4 += sd4; while (sin4 > pi2 || sin4 < 0) sin4 -= pi2;
  437.     sin5 += sd5; while (sin5 > pi2 || sin5 < 0) sin5 -= pi2;
  438.     sin6 += sd6; while (sin6 > pi2 || sin6 < 0) sin6 -= pi2;
  439.  
  440.     for (i = 0; i < 10; ++i)
  441.     {
  442.         x = (sin(sin1 + d1) + cos(sin2 + d2) + sin(sin3 + d3)) * 18 + 64;
  443.         y = (cos(sin4 + d4) + sin(sin5 + d5) + sin(sin6 + d5)) * 18 + 64;
  444.  
  445.         SETBOB((int)x, (int)y, intensity, intensity, intensity);
  446.         
  447.         d1 += dd1;
  448.         d2 += dd2;
  449.         d3 += dd3;
  450.         d4 += dd4;
  451.         d5 += dd5;
  452.         d6 += dd6;
  453.     }
  454.  
  455. }
  456.  
  457.  
  458.  
  459.  
  460. /*********************************************************************
  461. ----------------------------------------------------------------------
  462.  
  463.     mysticube
  464.     mainloop
  465.  
  466. ----------------------------------------------------------------------
  467. *********************************************************************/
  468.  
  469. void mainloop(struct Screen *scr, struct mvwindow *win)
  470. {
  471.     APTR timehandle = NULL;
  472.     int time;
  473.     char text[30];
  474.     BOOL timer = FALSE;
  475.     APTR ddh;
  476.     int frames = 0;
  477.     
  478.     ULONG *buffer;
  479.     APTR drawhandle;
  480.     BOOL finish = FALSE;
  481.     ULONG signals;
  482.     struct IntuiMessage *imsg;
  483.  
  484.     SetABPenDrMd(win->window->RPort, 1,2, JAM2);
  485.  
  486.     drawhandle = ObtainDrawHandle(NULL, win->window->RPort,
  487.             scr->ViewPort.ColorMap, OBP_Precision, PRECISION_IMAGE, TAG_DONE);
  488.  
  489.     ddh = CreateDirectDrawHandle(drawhandle, 128,128, win->innerwidth, win->innerheight, NULL);
  490.  
  491.     buffer = AllocVec(128*128*4, MEMF_ANY+MEMF_CLEAR);
  492.  
  493.     if (ddh && buffer && drawhandle)
  494.     {
  495.         do
  496.         {
  497.             if (--frames < 0)
  498.             {
  499.                 initeffekt(buffer);
  500.                 frames = 200;
  501.             }
  502.         
  503.             effekt(buffer);
  504.     
  505.             signals = SetSignal(0, win->idcmpSignal | win->appSignal);
  506.     
  507.     
  508.             //    IDCMP message loop
  509.     
  510.             if (signals & win->idcmpSignal)
  511.             {
  512.                 while (imsg = (struct IntuiMessage *) GetMsg(win->window->UserPort))
  513.                 {
  514.                     ULONG iclass = imsg->Class;
  515.                     ULONG icode = imsg->Code;
  516.             
  517.                     ReplyMsg((struct Message *) imsg);
  518.             
  519.                     switch (iclass)
  520.                     {
  521.                         case CLOSEWINDOW:
  522.                             finish = TRUE;
  523.                             break;
  524.             
  525.                         case NEWSIZE:
  526.                             if ((win->window->Width != win->winwidth) ||
  527.                                 (win->window->Height != win->winheight))
  528.                             {
  529.                                 UpdateWindowParameters(win);
  530.                                 DeleteDirectDrawHandle(ddh);
  531.                                 ddh = CreateDirectDrawHandle(drawhandle, 128,128, win->innerwidth, win->innerheight, NULL);
  532.                             }
  533.                             break;
  534.     
  535.                         case VANILLAKEY:
  536.                             switch (icode)
  537.                             {
  538.                                 case 27:
  539.                                     finish = TRUE;
  540.                                     break;
  541.     
  542.                                 case 32:
  543.                                     initeffekt(buffer);
  544.                                     frames = 200;
  545.                                     break;
  546.     
  547.                                 case 't':
  548.                                     timer = timer ? FALSE : TRUE;
  549.                                     break;
  550.                             }
  551.                     }
  552.             
  553.                 }
  554.             }
  555.     
  556.     
  557.             //    get 1/1000 seconds since last frame
  558.     
  559.             if (timehandle)
  560.             {
  561.                 time = timerstop(timehandle);
  562.             }
  563.             else
  564.             {
  565.                 time = 0;
  566.             }
  567.     
  568.     
  569.             //    start timer
  570.     
  571.             timehandle = timerstart();
  572.     
  573.     
  574.             //    draw
  575.     
  576.             if (buffer)
  577.             {
  578.                 DirectDrawTrueColor(ddh, buffer, win->innerleft, win->innertop, NULL);
  579.     
  580.                 if (timer)
  581.                 {
  582.                     //    display frames per second
  583.         
  584.                     Move(win->window->RPort, win->innerleft, 
  585.                         win->innertop + win->innerheight - win->window->RPort->TxHeight + win->window->RPort->TxBaseline);
  586.                     sprintf(text, "fps: %ld", (ULONG) ((double) 1000 / (double) time));
  587.                     Text(win->window->RPort, text, strlen(text));
  588.                 }
  589.             }
  590.     
  591.     
  592.         } while (finish == FALSE);
  593.     }
  594.  
  595.     if (buffer) FreeVec(buffer);
  596.     if (ddh) DeleteDirectDrawHandle(ddh);
  597.     if (drawhandle) ReleaseDrawHandle(drawhandle);
  598. }
  599.  
  600.  
  601.  
  602. /*********************************************************************
  603. ----------------------------------------------------------------------
  604.  
  605.     main
  606.  
  607. ----------------------------------------------------------------------
  608. *********************************************************************/
  609.  
  610. ULONG main (int argc, char **argv)
  611. {
  612.     ULONG result;
  613.  
  614.     if(InitGlobal())
  615.     {
  616.         struct mvwindow *window;
  617.         struct Screen *defscreen;
  618.  
  619.         if (defscreen = LockPubScreen(NULL))
  620.         {
  621.             if (window = CreateMVWindow(defscreen))
  622.             {
  623.                 SetTaskPri(FindTask(NULL), TASKPRIO);
  624.                 mainloop(defscreen, window);
  625.                 DeleteMVWindow(window);
  626.                 result = 0;
  627.             }
  628.             else
  629.             {
  630.                 printf("*** window could not be opened\n");
  631.                 result = 20;
  632.             }
  633.  
  634.             UnlockPubScreen(NULL, defscreen);
  635.         }
  636.         else
  637.         {
  638.             printf("*** pubscreen could not be locked\n");
  639.             result = 20;
  640.         }
  641.         
  642.         CloseGlobal();
  643.     }
  644.     else
  645.     {
  646.         printf("*** global initialization failed\n");
  647.         result = 20;
  648.     }
  649.     
  650.     return result;
  651. }
  652.